package com.example.demofdfs.web.websocket;

import java.io.IOException;

import com.alibaba.fastjson.JSON;

/**
 * 推送消息到客户端
 *
 */
public class WebSocketUtil {

	/**
	 * 
	 * @param userId	用户id
	 * @param obj		发送数据对象
	 * @throws IOException
	 */
	public static void send(String userId, Object obj) throws IOException {
		WebSocketServer socketServer = WebSocketServer.getSession(userId);
//		Objects.requireNonNull(socketServer);
		if (socketServer != null) {
			socketServer.sendMessage(JSON.toJSONString(obj));
		}
	}
}
